package com.honey.generator.java;

import org.java.plugin.PluginLifecycleException;

import com.honey.compilation.java.Field;
import com.honey.compilation.java.InnerClass;
import com.honey.compilation.java.InnerEnum;
import com.honey.compilation.java.Method;
import com.honey.compilation.java.StaticBlock;
import com.honey.core.Extension;
import com.honey.core.NullPlugin;
import com.honey.core.utils.ObjectFactory;
import com.honey.generator.java.extension.point.AddFieldListener;
import com.honey.generator.java.extension.point.AddInnerClassListener;
import com.honey.generator.java.extension.point.AddInnerEnumListener;
import com.honey.generator.java.extension.point.AddMethodListener;
import com.honey.generator.java.extension.point.AddStaticBlockListener;
import com.honey.generator.java.extension.point.BeginClassListener;
import com.honey.generator.java.extension.point.BeginFieldListener;
import com.honey.generator.java.extension.point.BeginFileCommentListener;
import com.honey.generator.java.extension.point.BeginImportListener;
import com.honey.generator.java.extension.point.BeginInnerClassListener;
import com.honey.generator.java.extension.point.BeginInnerEnumListener;
import com.honey.generator.java.extension.point.BeginMethodListener;
import com.honey.generator.java.extension.point.BeginStaticBlockListener;
import com.honey.generator.java.extension.point.GeneratorJavaClass;

public class GeneratorJavaClassPlugin extends NullPlugin{
	
	private static final String GENERATOR_JAVA_CLASS ="GeneratorJavaClass";  
	
	private static final String ADD_FIELD_LISTENER ="AddFieldListener";
	
	private static final String ADD_METHOD_LISTENER = "AddMethodListener";
	
	private static final String ADD_STATIC_BLOCK_LISTENER = "AddStaticBlockListener";
	
	private static final String ADD_INNER_CLASS_LISTENER = "AddInnerClassListener";
	
	private static final String ADD_INNER_ENUM_LISTENER = "AddInnerEnumListener";
	
	private static final String BEGIN_CLASS_LISTENER = "BeginClassListener";
	
	private static final String BEGIN_FIELD_LISTENER = "BeginFieldListener";
	
	private static final String BEGIN_FILE_COMMENT_LISTENER = "BeginFileCommentListener";
	
	private static final String BEGIN_IMPORT_LISTENER = "BeginImportListener";
	
	private static final String BEGIN_INNER_CLASS_LISTENER = "BeginInnerClassListener";
	
	private static final String BEGIN_INNER_ENUM_LISTENER = "BeginInnerEnumListener";
	
	private static final String BEGIN_METHOD_LISTENER = "BeginMethodListener";
	
	private static final String BEGIN_STATIC_BLOCK_LISTENER = "BeginStaticBlockListener";
	
	private GeneratorJavaClass[] generatorJavaClasses = null;
	
	/** 添加属性事件监听处理链 */
	private AddFieldListener<Field>[] addFieldListenerChain = null;
	
	/** 添加方法事件监听处理链 */
	private AddMethodListener<Method>[] addMethodListenerChain = null;
	
	/** 添加静态块事件监听处理链 */
	private AddStaticBlockListener<StaticBlock>[] addStaticBlockListenerChain = null;
	
	/** 添加内部类事件监听处理链 */
	private AddInnerClassListener<InnerClass>[] addInnerClassListenerChain = null;
	
	/** 添加内部枚举事件监听处理链 */
	private AddInnerEnumListener<InnerEnum>[] addInnerEnumListenerChain = null;
	
	/** 开始添加类注释事件监听处理链 */
	private BeginClassListener[] beginClassListenerChain = null;

	/** 开始添加属性事件监听处理链 */
	private BeginFieldListener[] beginFieldListenerChain = null;
	
	/** 开始添加java文件注释事件监听处理链 */
	private BeginFileCommentListener[] beginFileCommentListenerChain = null;
	
	/** 开始导入包事件监听处理链 */
	private BeginImportListener[] beginImportListenerChain = null;
	
	/** 开始内部类事件监听处理链 */
	private BeginInnerClassListener[] beginInnerClassListenerChain = null;
	
	/** 开始内部枚举事件监听处理链 */
	private BeginInnerEnumListener[] beginInnerEnumListenerChain = null;

	/** 开始方法区域事件监听处理链 */
	private BeginMethodListener[] beginMethodListenerChain = null;

	/** 开始静态块事件监听处理链 */
	private BeginStaticBlockListener[] beginStaticBlockListenerChain = null;
	
	/** java 项目工作空间 */
	//private String targetProjectWorkeySpace;
	
	/** src文件地址 */
	//private String targetSrcDirectory;
	
	/** 根包的名称(包名最后带有"."号) */
	//private String rootPackage;
	
	//private boolean isForcePrimitiveType = true;
	
	/** 存储类型 */
	//private  StorageType storageType = StorageType.BACKUP_STORAGE; 
	
	//private String charset="UTF-8" ;
	
	public GeneratorJavaClass[] getGeneratorJavaClass() throws PluginLifecycleException{
		if(generatorJavaClasses == null ){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, GENERATOR_JAVA_CLASS);
			generatorJavaClasses = new GeneratorJavaClass[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				generatorJavaClasses[i]=(GeneratorJavaClass)extension;
				i++ ;
			}
		}
		return generatorJavaClasses;
	}
	
	/**
	 * 获取添加属性事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public AddFieldListener<Field>[] getAddFieldListener()throws PluginLifecycleException{		
		if(addFieldListenerChain == null ){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, ADD_FIELD_LISTENER);
			addFieldListenerChain = new AddFieldListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				addFieldListenerChain[i]=(AddFieldListener<Field>)extension;
				i++ ;
			}
		}
		return addFieldListenerChain;
	}
	
	/**
	 * 获取添加方法事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public AddMethodListener<Method>[] getAddMethodListener()throws PluginLifecycleException{		
		if( addMethodListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, ADD_METHOD_LISTENER);
			addMethodListenerChain = new AddMethodListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				addMethodListenerChain[i]=(AddMethodListener<Method>)extension;
				i++ ;
			}
		}
		return addMethodListenerChain;
	}
	
	/**
	 * 获取添加静态块事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public AddStaticBlockListener<StaticBlock>[] getAddStaticBlockListener()throws PluginLifecycleException{		
		if( addStaticBlockListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, ADD_STATIC_BLOCK_LISTENER);
			addStaticBlockListenerChain = new AddStaticBlockListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				addStaticBlockListenerChain[i]=(AddStaticBlockListener<StaticBlock>)extension;
				i++ ;
			}
		}
		return addStaticBlockListenerChain;
	}
	
	/**
	 * 获取添加内部类事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public AddInnerClassListener<InnerClass>[] getAddInnerClassListener()throws PluginLifecycleException{		
		if( addInnerClassListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, ADD_INNER_CLASS_LISTENER);
			addInnerClassListenerChain = new AddInnerClassListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				addInnerClassListenerChain[i]=(AddInnerClassListener<InnerClass>)extension;
				i++ ;
			}
		}
		return addInnerClassListenerChain;
	}
	
	/**
	 * 获取添加内部类事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public AddInnerEnumListener<InnerEnum>[] getAddInnerEnumListener()throws PluginLifecycleException{		
		if( addInnerEnumListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, ADD_INNER_ENUM_LISTENER);
			addInnerEnumListenerChain = new AddInnerEnumListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				addInnerEnumListenerChain[i]=(AddInnerEnumListener<InnerEnum>)extension;
				i++ ;
			}
		}
		return addInnerEnumListenerChain;
	}

	/**
	 * 获取开始添加类注释事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public BeginClassListener[] getBeginClassListener()throws PluginLifecycleException{		
		if( beginClassListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, BEGIN_CLASS_LISTENER);
			beginClassListenerChain = new BeginClassListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				beginClassListenerChain[i]=(BeginClassListener)extension;
				i++ ;
			}
		}
		return beginClassListenerChain;
	}
	
	/**
	 * 获取开始添加属性事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public BeginFieldListener[] getBeginFieldListener()throws PluginLifecycleException{		
		if( beginFieldListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, BEGIN_FIELD_LISTENER);
			beginFieldListenerChain = new BeginFieldListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				beginFieldListenerChain[i]=(BeginFieldListener)extension;
				i++ ;
			}
		}
		return beginFieldListenerChain;
	}
	
	/**
	 * 获取开始添加java文件注释事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public BeginFileCommentListener[] getBeginFileCommentListener()throws PluginLifecycleException{		
		if( beginFileCommentListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, BEGIN_FILE_COMMENT_LISTENER);
			beginFileCommentListenerChain = new BeginFileCommentListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				beginFileCommentListenerChain[i]=(BeginFileCommentListener)extension;
				i++ ;
			}
		}
		return beginFileCommentListenerChain;
	}

	/**
	 * 获取开始导入包事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public BeginImportListener[] getBeginImportListener()throws PluginLifecycleException{		
		if( beginImportListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, BEGIN_IMPORT_LISTENER);
			beginImportListenerChain = new BeginImportListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				beginImportListenerChain[i]=(BeginImportListener)extension;
				i++ ;
			}
		}
		return beginImportListenerChain;
	}
	
	/**
	 * 获取开始内部类事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public BeginInnerClassListener[] getBeginInnerClassListener()throws PluginLifecycleException{		
		if( beginInnerClassListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, BEGIN_INNER_CLASS_LISTENER);
			beginInnerClassListenerChain = new BeginInnerClassListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				beginInnerClassListenerChain[i]=(BeginInnerClassListener)extension;
				i++ ;
			}
		}
		return beginInnerClassListenerChain;
	}
	public BeginInnerEnumListener[] getBeginInnerEnumListener()throws PluginLifecycleException{		
		if( beginInnerEnumListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, BEGIN_INNER_ENUM_LISTENER);
			beginInnerEnumListenerChain = new BeginInnerEnumListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				beginInnerEnumListenerChain[i]=(BeginInnerEnumListener)extension;
				i++ ;
			}
		}
		return beginInnerEnumListenerChain;
	}
	
	/**
	 * 获取开始方法区域事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public BeginMethodListener[] getBeginMethodListener()throws PluginLifecycleException{		
		if( beginMethodListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, BEGIN_METHOD_LISTENER);
			beginMethodListenerChain = new BeginMethodListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				beginMethodListenerChain[i]=(BeginMethodListener)extension;
				i++ ;
			}
		}
		return beginMethodListenerChain;
	}
	
	/**
	 * 获取开始静态块事件监听处理链
	 * @return
	 * @throws PluginLifecycleException
	 */
	public BeginStaticBlockListener[] getBeginStaticBlockListener()throws PluginLifecycleException{		
		if( beginStaticBlockListenerChain ==  null){
			Extension<GeneratorJavaClassPlugin>  []extensions = ObjectFactory.getExtensionClasses(this, BEGIN_STATIC_BLOCK_LISTENER);
			beginStaticBlockListenerChain = new BeginStaticBlockListener[extensions.length] ;
			int i =0;
			for(Extension<GeneratorJavaClassPlugin> extension : extensions){
				beginStaticBlockListenerChain[i]=(BeginStaticBlockListener)extension;
				i++ ;
			}
		}
		return beginStaticBlockListenerChain;
	}
	
	
}
